Skip to content

Fix webpack filesystem cache script recovery#190

Draft
davidmurdoch wants to merge 1 commit into
webdiscus:masterfrom
davidmurdoch:codex/fix-webpack-cache-recovery
Draft

Fix webpack filesystem cache script recovery#190
davidmurdoch wants to merge 1 commit into
webdiscus:masterfrom
davidmurdoch:codex/fix-webpack-cache-recovery

Conversation

@davidmurdoch
Copy link
Copy Markdown

@davidmurdoch davidmurdoch commented May 26, 2026

Summary

  • make the plugin persistent cache restore synchronous with Webpack compilation setup
  • only persist plugin collection cache after successful compilations
  • recover missing script collection state from Webpack cached chunk graph when a cached HTML module still requires an existing script
  • validate deserialized collection cache shape and discard incompatible plugin cache data
  • enable the existing filesystem-cache JS fixture as a two-run application-level regression test

Root cause

Webpack can restore cached HTML template modules that still contain generated require(...) calls for script resources while the plugin collection cache is incomplete or stale. In that state the script file exists, but the plugin resolver no longer has script bookkeeping for it and throws a false Cannot resolve ... error during render manifest generation.

A deterministic minimal reproduction is the existing test/cases/cache-filesystem-js fixture: its js.filename option is a function. On master, the first build skips the plugin persistent cache as non-serializable, then the second build restores Webpack cached HTML modules without the plugin collection state and fails resolving src/main.js.

Validation

  • node -c src/Plugin/AssetCompiler.js && node -c src/Plugin/Collection.js && node -c src/Plugin/Resolver.js
  • node -c test/utils/helpers.js
  • npm test -- --runTestsByPath ./test/unit.test.js
  • npm test -- --runTestsByPath ./test/integration.test.js -t "cache|use script in html"

@davidmurdoch
Copy link
Copy Markdown
Author

@webdiscus I don't really intend for you to merge this PR. It's 100% AI coded, and I'm not really sure if the fixes it came up with are valid.

@webdiscus
Copy link
Copy Markdown
Owner

Hello @davidmurdoch,

thanks for the issue reporting and the PR. I will review it.

I know, your project is very big, however I need a small as possible repo with reproducible issue, containing all needed files. As base you can take the issue-0-base-template. Please describe the steps to reproduce the issue.

The unit test is not enough. I need to see the problem on application level. Help me to reproduce your pain by me local.

Thanks.

@davidmurdoch davidmurdoch force-pushed the codex/fix-webpack-cache-recovery branch from f850ff1 to 6c3e64d Compare May 26, 2026 18:57
@davidmurdoch
Copy link
Copy Markdown
Author

I found a deterministic minimal reproduction using the existing small cache fixture in this repository; it does not require MetaMask or timing Ctrl+C.

Steps on current master:

npm ci
cd test/cases/cache-filesystem-js
rm -rf .cache dist
npx webpack --config webpack.config.js
npx webpack --config webpack.config.js

Observed on the second build from master:

HTML Bundler Plugin  Can't resolve .../test/cases/cache-filesystem-js/src/main.js in the file src/index.html

The first build succeeds but Webpack warns that html-bundler-webpack-plugin|PersistentCache was skipped because js.filename in this fixture is a function. The second build then reuses Webpack cached HTML module code containing require(.../src/main.js), but the plugin collection cache was not restored, so the resolver treats the existing script file as missing.

I pushed an update to this PR that turns this into an application-level regression test by making compareFilesRuns() run sequentially and enabling filesystem-js-runs_n2. That test fails on master with the error above and passes on this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants